package com.ethan.cj.ssm.controller;

import com.ethan.cj.ssm.entity.Claim;
import com.ethan.cj.ssm.service.ClaimService;
import com.ethan.cj.ssm.util.JsonUtil;
import com.ethan.cj.ssm.util.PageBean;
import lombok.extern.log4j.Log4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

/**
 * 分类管理控制层
 */
@Controller
@Log4j
@RequestMapping("claim")
public class ClaimController {

    /**
     * 债权打包service层映射
     */
    @Autowired
    private ClaimService cs;

    /**
     * 进入主页面
     *
     * @return
     */
    @RequestMapping("list")
    public String list() {
        return "lw/claimhome";
    }

    /**
     * 分页查询
     *
     * @param page   页数
     * @param params 查询条件
     * @return 前端字符串
     */
    @RequestMapping("/claimPage")
    @ResponseBody
    public Map<Object,Object> claimPage(
            @RequestParam("page") int page
            , @RequestParam("limit") int limit
            , @RequestParam(value = "params", required = false) String params) {
        Map map = JsonUtil.parseObject(params, Map.class);
        PageBean<Claim> pb = new PageBean<>(page, limit);
        return cs.selectClaim(pb, map);
    }

    /**
     * 查询债权打包所有信息
     * @return 债权打包 json对象
     */
    @RequestMapping("/claimList")
    @ResponseBody
    public Map<Object,Object> claimList() {
        return cs.selClaimList();
    }
}
